// logs.js
// const util = require('../../utils/util.js')
import {
    baseUrl,
    isHaveToken,
    isLogin,
    javaUrl
} from "../../../utils/util";
Page({
    data: {
        // logs: [],
        // text1: "",
        // text2: "",
        // from: "",
        current: 1,
        autoplay: true,
        duration: 500,
        interval: 5000,
        course: [],
        phone: "",
        pwd: "",
        swiperList: [
            {
                image: `https://wechat-label.oss-cn-guangzhou.aliyuncs.com/top_img.png`,
            },
            {
                image: `https://wechat-label.oss-cn-guangzhou.aliyuncs.com/top_img.png`,
            },
        ]
    },

    swiperDetail(e) {

        // if(e.currentTarget.dataset.index==1){
        //     console.log("这是第一张图片",e)
        // }
        switch (e.currentTarget.dataset.index) {
            case e.currentTarget.dataset.index = 0:
                console.log("这是第一张图片", e.currentTarget.dataset.index);
                wx.navigateTo({
                  url: '../info/info',
                })
                break;
            case e.currentTarget.dataset.index = 1:
                console.log("这是第2张图片");
                wx.navigateTo({
                    url: '../info/info',
                  })
                break;
            case e.currentTarget.dataset.index = 2:
                console.log("这是第3张图片");
                wx.navigateTo({
                    url: '../info/info',
                  })
                break;
            case e.currentTarget.dataset.index = 3:
                console.log("这是第4张图片");
                wx.navigateTo({
                    url: '../info/info',
                  })
                break;
            case e.currentTarget.dataset.index = 4:
                console.log("这是第5张图片");
                wx.navigateTo({
                    url: '../info/info',
                  })
                break;
            default: console.log("e", e.currentTarget.dataset.index)
        }

    },
    gotoDetail(event) {
        console.log("event", event)
        // var course=event.currentTarget.dataset.detail
        var class_id = event.currentTarget.dataset.class_id
        var course_id = event.currentTarget.dataset.course_id
        var class_name = event.currentTarget.dataset.class_name
        var class_teacher = event.currentTarget.dataset.class_teacher
        var class_img = event.currentTarget.dataset.class_img
        console.log("course", event.currentTarget.dataset.detail)
        wx.navigateTo({
            url: `../course_detail/course_detail?class_id=${class_id}&course_id=${course_id}&class_teacher=${class_teacher}&class_name=${class_name}&class_img=${class_img}`,
        })
    },

    getCourse() {
        var that = this
        wx.request({
            url: `${javaUrl}/xxt/login/getCourse/${that.data.phone}/${that.data.pwd}`,
            method: 'GET',
            success(res) {
                console.log(res)
                that.setData({
                    course: res.data.data.course
                })
            }
        })

    },
    onLoad() {
        var that = this
        if (isLogin()) {
            if (that.data.course.length == 0) {
                wx.showToast({
                    title: '加载中',
                    duration: 1000,
                    icon: 'loading',
                    success: (res) => { },
                    fail: (res) => { },
                    complete: (res) => { },
                })
            }
            console.log('isLogin')
            that.setData({
                pwd: wx.getStorageSync('pwd'),
                phone: wx.getStorageSync('phone')
            })
            that.getCourse()
        } else {
            wx.reLaunch({
                url: '/pages/xuexitong/my/my',
            })
        }
    },
    onPullDownRefresh() {
        var that = this
        if (isLogin()) {
            console.log('isLogin')
            that.setData({
                pwd: wx.getStorageSync('pwd'),
                phone: wx.getStorageSync('phone')
            })
            that.getCourse()
        } else {
            wx.navigateTo({
                url: '/pages/xuexitong/my/my',
            })
        }
    }
})
